// tic-tac-toc

#include <stdio.h>

int judgeResult(int numOfO, int numOfX, int size);
int checkResult(int size, int board[size][size]);

int main(int argc, char const *argv[])
{
    const int size = 3;
    int board[size][size];
    int i, j;
    int numOfX;
    int numOfO;
    int result = -1;    // -1：没人赢；1：X赢；0：O赢

    // 读入矩阵
    for (i = 0; i < size; i++)
    {
        for (j = 0; j < size; j++)
        {
            scanf("%d", &board[i][j]);
        }
    }

    result = checkResult(size, board);

    if (result == -1)
    {
        numOfO = numOfX = 0;
        for (i = 0; i < size; i++)
        {
            if (board[i][i] == 1)
            {
                numOfX++;
            }
            else
            {
                numOfO++;
            }
        }
        result = judgeResult(numOfO, numOfX, size);
    }

    if (result == -1)
    {
        numOfO = numOfX = 0;
        for (i = 0; i < size; i++)
        {
            if (board[i][-i] == 1)
            {
                numOfX++;
            }
            else
            {
                numOfO++;
            }
        }
        result = judgeResult(numOfO, numOfX, size);
    }
    

    printf("%d\n", result);

    return 0;
}

int judgeResult(int numOfO, int numOfX, int size)
{
    int result = -1;

    if (numOfO == size)
    {
        result = 0;
    }
    else if (numOfX == size)
    {
        result = 1;
    }

    return result;
}

int checkResult(int size, int board[size][size])
{
    int result = -1;
    int numOfX_col, numOfX_row, numOfO_col, numOfO_row;
    // 检索
    for (int i = 0; i < size && result == -1; i++)
    {
        numOfO_row = numOfO_col = numOfX_row = numOfX_col = 0;
        for (int j = 0; j < size; j++)
        {
            // 按行计数
            if (board[i][j] == 1)
            {
                numOfX_row++;
            }
            else
            {
                numOfO_row++;
            }
            // 按列计数
            if (board[j][i] == 1)
            {
                numOfX_col++;
            }
            else
            {
                numOfO_col++;
            }
        }
        // 每检查完一行判断胜负
        result = judgeResult(numOfO_col, numOfX_col, size);
        // 按列判断胜负
        if (result == -1)
        {
            result = judgeResult(numOfO_row, numOfX_row, size);
        }
    }

    return result;
}